﻿using System;
using System.Configuration;
using System.Net.Mime;
using System.Security.Cryptography;
using System.Windows;


namespace YwangHRMSys.DBUtility
    {
        public class CommonHelper
            {


                #region 运用与MD5的加密


                public static string GetMD5(string sDataIn)
                {
                    var md5 = new MD5CryptoServiceProvider();
                    byte[] bytValue, bytHash;
                    bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
                    bytHash = md5.ComputeHash(bytValue);
                    md5.Clear();
                    string sTemp = "";
                    for (int i = 0; i < bytHash.Length; i++)
                    {
                        sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
                    }
                    return sTemp.ToLower();
                }
                #endregion

                #region MD5加盐的盐
                /// <summary>
                /// 把一些可能会变的值写入App.config
                /// </summary>
                /// <returns></returns>
                public static string GetPasswordSalt()
                {
                    string salt = ConfigurationManager.AppSettings["passwordSalt"];
                    return salt;
                }

                #endregion
                #region 获得登录用户的ID
                /// <summary>
                /// 获得登录用户的ID
                /// </summary>
                /// <returns></returns>
                public static Guid GetOperatorId()
                {
                
                    Guid operatorid = (Guid)Application.Current.Properties["将登录用户信息存储到内存中"];
                    return operatorid;
                }
                #endregion


            }
    }